package com.coocaa.ops.api.base.third;

import feign.Client;
import feign.Contract;
import feign.okhttp.OkHttpClient;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;

/**
 * 公共的feign配置，在特定的feign配置类里面注入下面的bean
 * @author tangminghong
 * @date 2020-04-12 17:29
 */
@Configuration
public class CommonFeignConfig {

    /**
     * 使用SpringMVC的约定，即 使用SpringMVC的注解
     * @return
     */
    @Bean
    @Primary
    public Contract defaultContract() {
        return new SpringMvcContract();
    }

    /**
     * 使用okhttp
     * @return
     */
    @Bean
    @Primary
    @Scope("prototype")
    public Client defaultClient() {
        return new OkHttpClient();
    }

}
